#!/bin/bash

# while-menu-dialog: a menu driven system information program

DIALOG_CANCEL=1
DIALOG_ESC=255
HEIGHT=0
WIDTH=0

display_result() {
  dialog --title "$1" \
    --no-collapse \
    --msgbox "$result" 0 0
}

while true; do
  exec 3>&1
  selection=$(dialog \
    --backtitle "Void installer v1.1" \
    --title "Menu" \
    --clear \
    --cancel-label "Exit" \
    --menu "Please select:" $HEIGHT $WIDTH 4 \
    "1" "Inspect" \
    "2" "Update" \
    "3" "Install" \
    2>&1 1>&3)
  exit_status=$?
  exec 3>&-
  case $exit_status in
    $DIALOG_CANCEL)
      clear
      echo "Program terminated."
      exit
      ;;
    $DIALOG_ESC)
      clear
      echo "Program aborted." >&2
      exit 1
      ;;
  esac
  case $selection in
    1 )
      vim void
      ;;
    2 )
      sudo xbps-install -Syu
      ;;
    3 )
      sudo xbps-install abiword abook acpi apulse alsa-plugins-pulseaudio alsa-tools alsa-utils arc-theme bash-completion bc btop ca-certificates calcurse cargo cmus cups cups-browsed curl dunst dvtm epson-inkjet-printer-escpr ethtool feh firefox flashrom fluxbox font-hack-ttf geary gettext github-cli gnumeric gufw htop inxi isync jgmenu lxappearance mpv msmtp NetworkManager network-manager-applet neomutt nerd-fonts-symbols-ttf neofetch nextcloud-client nyxt octoxbps papirus-icon-theme pass pcmanfm polkit pcsc-ccid pcsc-tool pcsclite spython3-pip ranger redshift redshift-gtk rofi rust scribus scrot slim smartmontools sxhkd thunderbird tlp tlp-rdw transset ueberzug ufw unzip usbutils util-linux vifm vim volumeicon wget xautolock xcompmgr xdg-user-dirs xdg-user-dirs-gtk xdg-utils xf86-input-synaptics xcalc xinit xorg xorg-server xterm zathura zathura-pdf-poppler zsh
      ;;
  esac
done
